﻿namespace Hidistro.UI.Web.Admin
{
    using Hidistro.ControlPanel.Commodities;
    using Hidistro.ControlPanel.Store;
    using Hidistro.Core;
    using Hidistro.Entities.Commodities;
    using Hidistro.Entities.Store;
    using Hidistro.UI.Common.Controls;
    using Hishop.Components.Validation;
    using kindeditor.Net;
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using wnxd_feature;
    using CustomMade;
    using System.Data;
    using System.Web.UI;
    using wnxd.javascript;
    using System.Reflection;
    [PrivilegeCheck(Privilege.EditProducts)]
    public class EditProduct : ProductBasePage
    {
        protected Button btnSave;
        private int categoryId;
        protected CheckBox ChkisfreeShipping;
        protected CheckBox CheckStraightdown;
        protected CheckBox chkSkuEnabled;
        protected CheckBox ckbIsDownPic;
        protected BrandCategoriesDropDownList dropBrandCategories;
        protected ProductTypeDownList dropProductTypes;
        protected KindeditorControl fckDescription;
        protected KindeditorControl fckmobbileDescription;
        protected HtmlGenericControl l_tags;
        protected Literal litCategoryName;
        protected ProductTagsLiteral litralProductTag;
        protected HyperLink lnkEditCategory;
        private int productId;
        protected RadioButton radInStock;
        protected RadioButton radOnSales;
        protected RadioButton radUnSales;
        protected Script Script1;
        protected Script Script2;
        protected TrimTextBox txtAttributes;
        protected TrimTextBox txtCostPrice;
        protected TrimTextBox txtDisplaySequence;
        protected TrimTextBox txtMarketPrice;
        protected TrimTextBox txtMemberPrices;
        protected TrimTextBox txtMetaDescription;
        protected TrimTextBox txtMetaKeywords;
        protected TrimTextBox txtMeta_Title;
        protected TrimTextBox txtMeta_Alt;
        protected TrimTextBox txtProductCode;
        protected TrimTextBox txtProductName;
        protected TrimTextBox txtProductTitle;
        protected TrimTextBox txtProductTag;
        protected TrimTextBox txtSalePrice;
        protected TrimTextBox txtShortDescription;
        protected TrimTextBox txtSku;
        protected TrimTextBox txtSkus;
        protected TrimTextBox txtStock;
        protected TrimTextBox txtTitle;
        protected TrimTextBox txtUnit;
        protected TrimTextBox txtWeight;

        protected TrimTextBox txtzdms;
        protected TrimTextBox txtkzfs;
        protected TrimTextBox txtsyfs;
        protected TrimTextBox txtgdfs;
        protected TrimTextBox txtfsxn;

        protected TrimTextBox txtztcz;
        protected TrimTextBox txtczcg;
        protected TrimTextBox txtspcd;

        protected TrimTextBox txtcrcd;
        protected TrimTextBox txtzdzj;
        protected TrimTextBox txtzxzj;
        protected TrimTextBox txtspys;
        protected TrimTextBox txtspgg;
        protected TrimTextBox txtspmz;
        protected TrimTextBox txtspjz;

        protected TrimTextBox txtspbh;
        protected TrimTextBox txtspzb;
        protected TrimTextBox txtsprl;
        protected TrimTextBox txtspcf;
        protected TrimTextBox txtccfs;
        protected TrimTextBox txtrhsy;
        protected TrimTextBox txtsydx;

        protected HiddenField zdms;

        protected ImageUploader uploader1;
        protected ImageUploader uploader2;
        protected ImageUploader uploader3;
        protected ImageUploader uploader4;
        protected ImageUploader uploader5;
        protected ImageUploader uploader6;
        protected ImageUploader uploader7;
        protected ImageUploader uploader8;

        protected ImageUploader uploader9;

        feature wnxd = new feature();
        protected TrimTextBox txtShowSaleCounts;
        protected TrimTextBox txtVistiCounts;
        CustomMadeDao cm = new CustomMadeDao();

        public json json;
        private void btnSave_Click(object sender, EventArgs e)
        {

            int num;
            int num2;
            decimal num3;
            decimal? nullable;
            decimal? nullable2;
            decimal? nullable3;
            if (this.categoryId == 0)
            {
                this.categoryId = (int)this.ViewState["ProductCategoryId"];
            }
            if (this.ValidateConverts(this.chkSkuEnabled.Checked, out num, out num3, out nullable, out nullable2, out num2, out nullable3))
            {
                if (!this.chkSkuEnabled.Checked)
                {
                    if (num3 <= 0M)
                    {
                        this.ShowMsg("商品一口价必须大于0", false);
                        return;
                    }
                    if (nullable.HasValue && (nullable.Value >= num3))
                    {
                        this.ShowMsg("商品成本价必须小于商品一口价", false);
                        return;
                    }
                }
                string text = this.fckDescription.Text;
                string productDescrip = this.fckmobbileDescription.Text;
                if (this.ckbIsDownPic.Checked)
                {
                    text = base.DownRemotePic(text);
                    productDescrip = base.DownRemotePic(productDescrip);
                }
                Regex regex = new Regex("<script[^>]*?>.*?</script>", RegexOptions.IgnoreCase);
                ProductInfo target = new ProductInfo
                {

                    ProductId = this.productId,
                    CategoryId = this.categoryId,
                    TypeId = this.dropProductTypes.SelectedValue,
                    ProductName = this.txtProductName.Text,
                    ProductText = this.txtProductTitle.Text,
                    ProductCode = this.txtProductCode.Text,
                    DisplaySequence = num,
                    MarketPrice = nullable2,
                    Unit = this.txtUnit.Text,
                    ImageUrl1 = this.uploader1.UploadedImageUrl,
                    ImageUrl2 = this.uploader2.UploadedImageUrl,
                    ImageUrl3 = this.uploader3.UploadedImageUrl,
                    ImageUrl4 = this.uploader4.UploadedImageUrl,
                    ImageUrl5 = this.uploader5.UploadedImageUrl,
                    ImageUrl6 = this.uploader6.UploadedImageUrl,
                    ImageUrl7 = this.uploader7.UploadedImageUrl,
                    ImageUrl8 = this.uploader8.UploadedImageUrl,
                    ImageUrl9 = this.uploader9.UploadedImageUrl,
                    ThumbnailUrl40 = this.uploader1.ThumbnailUrl40,
                    ThumbnailUrl60 = this.uploader1.ThumbnailUrl60,
                    ThumbnailUrl100 = this.uploader1.ThumbnailUrl100,
                    ThumbnailUrl160 = this.uploader1.ThumbnailUrl160,
                    ThumbnailUrl180 = this.uploader1.ThumbnailUrl180,
                    ThumbnailUrl220 = this.uploader1.ThumbnailUrl220,
                    ThumbnailUrl310 = this.uploader1.ThumbnailUrl310,
                    ThumbnailUrl410 = this.uploader1.ThumbnailUrl410,
                    ShortDescription = this.txtShortDescription.Text,
                    IsfreeShipping = this.ChkisfreeShipping.Checked,
                    Description = (!string.IsNullOrEmpty(text) && (text.Length > 0)) ? regex.Replace(text, "") : null,
                    MobblieDescription = (!string.IsNullOrEmpty(productDescrip) && (productDescrip.Length > 0)) ? regex.Replace(productDescrip, "") : null,
                    Title = this.txtTitle.Text,
                    MetaDescription = this.txtMetaDescription.Text,
                    MetaKeywords = this.txtMetaKeywords.Text + "|" + this.txtMeta_Title.Text + "|" + this.txtMeta_Alt.Text,
                    AddedDate = DateTime.Now,
                    BrandId = this.dropBrandCategories.SelectedValue,
                    ShowSaleCounts = int.Parse(this.txtShowSaleCounts.Text),
                    VistiCounts = int.Parse(this.txtVistiCounts.Text)
                };
                ProductSaleStatus onSale = ProductSaleStatus.OnSale;
                if (this.radInStock.Checked)
                {
                    onSale = ProductSaleStatus.OnStock;
                }
                if (this.radUnSales.Checked)
                {
                    onSale = ProductSaleStatus.UnSale;
                }
                if (this.radOnSales.Checked)
                {
                    onSale = ProductSaleStatus.OnSale;
                }
                target.SaleStatus = onSale;
                CategoryInfo category = CatalogHelper.GetCategory(this.categoryId);
                if (category != null)
                {
                    target.MainCategoryPath = category.Path + "|";
                }
                Dictionary<string, SKUItem> skus = null;
                Dictionary<int, IList<int>> attrs = null;
                if (this.chkSkuEnabled.Checked)
                {
                    target.HasSKU = true;
                    skus = base.GetSkus(this.txtSkus.Text);
                }
                else
                {
                    Dictionary<string, SKUItem> dictionary3 = new Dictionary<string, SKUItem>();
                    SKUItem item = new SKUItem
                    {
                        SkuId = "0",
                        SKU = this.txtSku.Text,
                        SalePrice = num3,
                        CostPrice = nullable.HasValue ? nullable.Value : 0M,
                        Stock = num2,
                        Weight = nullable3.HasValue ? nullable3.Value : 0M
                    };
                    dictionary3.Add("0", item);
                    skus = dictionary3;
                    if (this.txtMemberPrices.Text.Length > 0)
                    {
                        base.GetMemberPrices(skus["0"], this.txtMemberPrices.Text);
                    }
                }
                if (!string.IsNullOrEmpty(this.txtAttributes.Text) && (this.txtAttributes.Text.Length > 0))
                {
                    attrs = base.GetAttributes(this.txtAttributes.Text);
                }
                ValidationResults validateResults = Hishop.Components.Validation.Validation.Validate<ProductInfo>(target);
                if (!validateResults.IsValid)
                {
                    this.ShowMsg(validateResults);
                }
                else
                {

                    json info = new json(this.Request.Form["json"]);
                    json Parameter = new json();
                    Parameter["update"] = new object[0];
                    Parameter["delete"] = new object[0];
                    Parameter["insert"] = new object[0];
                    foreach (KeyValuePair<string, json> t in info)
                    {
                        TrimTextBox tb = (TrimTextBox)(this.GetType().GetField("txt" + t.Key, BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this));
                        if (t.Value["NotNull"] != js.undefined && t.Value["NotNull"].Value)
                        {
                            ///修改
                            if (string.IsNullOrEmpty(tb.Text))
                            {
                                t.Value["NotNull"] = false;
                                Parameter["delete"].push(new { ProductId = this.productId, ParameterId = t.Value["ParameterId"] });
                            }
                            else
                            {
                                Parameter["update"].push(new { ValuesContent = tb.Text, ProductId = this.productId, ParameterId = t.Value["ParameterId"], });
                            }
                        }
                        else
                        {
                            ///新增
                            if (!string.IsNullOrEmpty(tb.Text))
                            {
                                t.Value["NotNull"] = true;
                                Parameter["insert"].push(new { ValuesContent = tb.Text, Namber = t.Value["Namber"], ProductId = this.productId, ParameterId = t.Value["ParameterId"], FatherId = t.Value["FatherId"], Code = t.Value["Namber"] });
                            }
                        }
                    }
                    this.json = info;
                    ProductHelper.ManageParameterValue(Parameter);

                    IList<int> tagIds = new List<int>();
                    if (!string.IsNullOrEmpty(this.txtProductTag.Text.Trim()))
                    {
                        string str3 = this.txtProductTag.Text.Trim();
                        string[] strArray = null;
                        if (str3.Contains(","))
                        {
                            strArray = str3.Split(new char[] { ',' });
                        }
                        else
                        {
                            strArray = new string[] { str3 };
                        }
                        foreach (string str4 in strArray)
                        {
                            tagIds.Add(Convert.ToInt32(str4));
                        }
                    }
                    if (Request.QueryString["copy"] != null)
                    {
                        switch (ProductHelper.AddProduct(target, skus, attrs, tagIds))
                        {
                            case ProductActionStatus.Success:
                                cm.Products_Update(target.ProductId, CheckStraightdown.Checked);
                                wnxd.ProductSet(target.ProductId, base.Request.Form["wnxd_feature[]"]);
                                this.ShowMsg("添加商品成功", true);
                                base.Response.Redirect(Globals.GetAdminAbsolutePath(string.Format("/product/AddProductComplete.aspx?categoryId={0}&productId={1}", this.categoryId, target.ProductId)), true);
                                return;

                            case ProductActionStatus.AttributeError:
                                this.ShowMsg("添加商品失败，保存商品属性时出错", false);
                                return;

                            case ProductActionStatus.DuplicateName:
                                this.ShowMsg("添加商品失败，商品名称不能重复", false);
                                return;

                            case ProductActionStatus.DuplicateSKU:
                                this.ShowMsg("添加商品失败，商家编码不能重复", false);
                                return;

                            case ProductActionStatus.SKUError:
                                this.ShowMsg("添加商品失败，商家规格错误", false);
                                return;

                            case ProductActionStatus.ProductTagEroor:
                                this.ShowMsg("添加商品失败，保存商品标签时出错", false);
                                return;
                        }
                        this.ShowMsg("添加商品失败，未知错误", false);
                    }
                    else
                    {
                        switch (ProductHelper.UpdateProduct(target, skus, attrs, tagIds))
                        {
                            case ProductActionStatus.Success:
                                cm.Products_Update(target.ProductId, CheckStraightdown.Checked);

                                wnxd.ProductSet(this.productId, base.Request.Form["wnxd_feature[]"]);
                                this.litralProductTag.SelectedValue = tagIds;
                                this.ShowMsg("修改商品成功", true);
                                return;

                            case ProductActionStatus.AttributeError:
                                this.ShowMsg("修改商品失败，保存商品属性时出错", false);
                                return;

                            case ProductActionStatus.DuplicateName:
                                this.ShowMsg("修改商品失败，商品名称不能重复", false);
                                return;

                            case ProductActionStatus.DuplicateSKU:
                                this.ShowMsg("修改商品失败，商家编码不能重复", false);
                                return;

                            case ProductActionStatus.SKUError:
                                this.ShowMsg("修改商品失败，商家编码不能重复", false);
                                return;

                            case ProductActionStatus.ProductTagEroor:
                                this.ShowMsg("修改商品失败，保存商品标签时出错", false);
                                return;
                        }
                        this.ShowMsg("修改商品失败，未知错误", false);
                    }
                }
            }
        }

        private void LoadProduct(ProductInfo product, Dictionary<int, IList<int>> attrs, ParameterValue pv)
        {



            //产品参数
            this.txtzdms.Text = pv.zdms;
            this.txtkzfs.Text = pv.kzfs;
            this.txtsyfs.Text = pv.syfs;
            this.txtgdfs.Text = pv.gdfs;
            this.txtfsxn.Text = pv.fsxn;
            this.txtztcz.Text = pv.ztcz;
            this.txtczcg.Text = pv.czcg;
            this.txtspcd.Text = pv.spcd;
            this.txtcrcd.Text = pv.crcd;
            this.txtzdzj.Text = pv.zdzj;
            this.txtzxzj.Text = pv.zxzj;
            this.txtspys.Text = pv.spys;
            this.txtspgg.Text = pv.spgg;
            this.txtspmz.Text = pv.spmz;
            this.txtspjz.Text = pv.spjz;
            this.txtspbh.Text = pv.spbh;
            this.txtspzb.Text = pv.spzb;
            this.txtsprl.Text = pv.sprl;
            this.txtspcf.Text = pv.spcf;
            this.txtccfs.Text = pv.ccff;
            this.txtrhsy.Text = pv.rhsy;
            this.txtsydx.Text = pv.sydx;

            this.json = pv.info;

            this.dropProductTypes.SelectedValue = product.TypeId;
            this.dropBrandCategories.SelectedValue = product.BrandId;
            this.txtDisplaySequence.Text = product.DisplaySequence.ToString();
            this.txtProductName.Text = Globals.HtmlDecode(product.ProductName);
            this.txtProductTitle.Text = Globals.HtmlDecode(product.ProductText);
            if (Request.QueryString["copy"] != null)
            {
                CategoryInfo category = CatalogHelper.GetCategory((int)this.ViewState["ProductCategoryId"]);
                if (category == null)
                {
                    base.GotoResourceNotFound();
                }
                else
                {
                    this.txtProductCode.Text = this.txtSku.Text = category.SKUPrefix + new Random(DateTime.Now.Millisecond).Next(1, 0x1869f).ToString(CultureInfo.InvariantCulture).PadLeft(5, '0');
                }
            }
            else
            {
                this.txtProductCode.Text = product.ProductCode;
                this.txtSku.Text = product.SKU;
            }
            this.txtUnit.Text = product.Unit;
            if (product.MarketPrice.HasValue)
            {
                this.txtMarketPrice.Text = product.MarketPrice.Value.ToString("F0");
            }
            this.txtShortDescription.Text = product.ShortDescription;
            this.ChkisfreeShipping.Checked = product.IsfreeShipping;
            DataTable dt = cm.GetStaightDownInfo(product.ProductId);
            string id = dt.Rows[0][0].ToString();
            if (!string.IsNullOrEmpty(id))
            {
                this.CheckStraightdown.Checked = Convert.ToBoolean(id);
            }
            this.fckDescription.Text = product.Description;
            this.fckmobbileDescription.Text = product.MobblieDescription;
            this.txtTitle.Text = product.Title;
            this.txtMetaDescription.Text = product.MetaDescription;
            string[] arr = product.MetaKeywords.Split('|');
            this.txtMetaKeywords.Text = arr[0];
            if (arr.Length > 1) this.txtMeta_Title.Text = arr[1];
            if (arr.Length > 2) this.txtMeta_Alt.Text = arr[2];


            this.txtShowSaleCounts.Text = product.ShowSaleCounts + "";
            this.txtVistiCounts.Text = product.VistiCounts + "";

            if (product.SaleStatus == ProductSaleStatus.OnSale)
            {
                this.radOnSales.Checked = true;
            }
            else if (product.SaleStatus == ProductSaleStatus.UnSale)
            {
                this.radUnSales.Checked = true;
            }
            else
            {
                this.radInStock.Checked = true;
            }
            this.uploader1.UploadedImageUrl = product.ImageUrl1;
            this.uploader2.UploadedImageUrl = product.ImageUrl2;
            this.uploader3.UploadedImageUrl = product.ImageUrl3;
            this.uploader4.UploadedImageUrl = product.ImageUrl4;
            this.uploader5.UploadedImageUrl = product.ImageUrl5;
            this.uploader6.UploadedImageUrl = product.ImageUrl6;
            this.uploader7.UploadedImageUrl = product.ImageUrl7;
            this.uploader8.UploadedImageUrl = product.ImageUrl8;

            this.uploader9.UploadedImageUrl = product.ImageUrl9;
            if ((attrs != null) && (attrs.Count > 0))
            {
                StringBuilder builder = new StringBuilder();
                builder.Append("<xml><attributes>");
                foreach (int num in attrs.Keys)
                {
                    builder.Append("<item attributeId=\"").Append(num.ToString(CultureInfo.InvariantCulture)).Append("\" usageMode=\"").Append(((int)ProductTypeHelper.GetAttribute(num).UsageMode).ToString()).Append("\" >");
                    foreach (int num2 in attrs[num])
                    {
                        builder.Append("<attValue valueId=\"").Append(num2.ToString(CultureInfo.InvariantCulture)).Append("\" />");
                    }
                    builder.Append("</item>");
                }
                builder.Append("</attributes></xml>");
                this.txtAttributes.Text = builder.ToString();
            }
            this.chkSkuEnabled.Checked = product.HasSKU;
            if (product.HasSKU)
            {
                StringBuilder builder2 = new StringBuilder();
                builder2.Append("<xml><productSkus>");
                foreach (string str in product.Skus.Keys)
                {
                    SKUItem item = product.Skus[str];
                    string str2 = ("<item skuCode=\"" + item.SKU + "\" salePrice=\"" + item.SalePrice.ToString("F0") + "\" costPrice=\"" + ((item.CostPrice > 0M) ? item.CostPrice.ToString("F0") : "") + "\" qty=\"" + item.Stock.ToString(CultureInfo.InvariantCulture) + "\" weight=\"" + ((item.Weight > 0M) ? item.Weight.ToString("F0") : "") + "\">") + "<skuFields>";
                    foreach (int num3 in item.SkuItems.Keys)
                    {
                        string[] strArray2 = new string[] { "<sku attributeId=\"", num3.ToString(CultureInfo.InvariantCulture), "\" valueId=\"", item.SkuItems[num3].ToString(CultureInfo.InvariantCulture), "\" />" };
                        string str3 = string.Concat(strArray2);
                        str2 = str2 + str3;
                    }
                    str2 = str2 + "</skuFields>";
                    if (item.MemberPrices.Count > 0)
                    {
                        str2 = str2 + "<memberPrices>";
                        foreach (int num4 in item.MemberPrices.Keys)
                        {
                            decimal num14 = item.MemberPrices[num4];
                            str2 = str2 + string.Format("<memberGrande id=\"{0}\" price=\"{1}\" />", num4.ToString(CultureInfo.InvariantCulture), num14.ToString("F0"));
                        }
                        str2 = str2 + "</memberPrices>";
                    }
                    str2 = str2 + "</item>";
                    builder2.Append(str2);
                }
                builder2.Append("</productSkus></xml>");
                this.txtSkus.Text = builder2.ToString();
            }
            SKUItem defaultSku = product.DefaultSku;
            this.txtSalePrice.Text = defaultSku.SalePrice.ToString("F0");
            this.txtCostPrice.Text = (defaultSku.CostPrice > 0M) ? defaultSku.CostPrice.ToString("F0") : "";
            this.txtStock.Text = defaultSku.Stock.ToString(CultureInfo.InvariantCulture);
            this.txtWeight.Text = (defaultSku.Weight > 0M) ? defaultSku.Weight.ToString("F0") : "";
            if (defaultSku.MemberPrices.Count > 0)
            {
                this.txtMemberPrices.Text = "<xml><gradePrices>";
                foreach (int num5 in defaultSku.MemberPrices.Keys)
                {
                    decimal num19 = defaultSku.MemberPrices[num5];
                    this.txtMemberPrices.Text = this.txtMemberPrices.Text + string.Format("<grande id=\"{0}\" price=\"{1}\" />", num5.ToString(CultureInfo.InvariantCulture), num19.ToString("F0"));
                }
                this.txtMemberPrices.Text = this.txtMemberPrices.Text + "</gradePrices></xml>";
            }
        }

        protected override void OnInitComplete(EventArgs e)
        {
            base.OnInitComplete(e);
            this.btnSave.Click += new EventHandler(this.btnSave_Click);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            int.TryParse(base.Request.QueryString["productId"], out this.productId);
            int.TryParse(base.Request.QueryString["categoryId"], out this.categoryId);

            if (!this.Page.IsPostBack)
            {
                Dictionary<int, IList<int>> dictionary;
                IList<int> tagsId = null;
                ParameterValue pv = ProductHelper.GetProductParameterValue(this.productId);
                ProductInfo product = ProductHelper.GetProductDetails(this.productId, out dictionary, out tagsId);
                if (product == null)
                {
                    base.GotoResourceNotFound();
                }
                else
                {
                    if (!string.IsNullOrEmpty(base.Request.QueryString["categoryId"]))
                    {
                        this.litCategoryName.Text = CatalogHelper.GetFullCategory(this.categoryId);
                        this.ViewState["ProductCategoryId"] = this.categoryId;
                        this.lnkEditCategory.NavigateUrl = "SelectCategory.aspx?categoryId=" + this.categoryId.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        this.litCategoryName.Text = CatalogHelper.GetFullCategory(product.CategoryId);
                        this.ViewState["ProductCategoryId"] = product.CategoryId;
                        this.lnkEditCategory.NavigateUrl = "SelectCategory.aspx?categoryId=" + product.CategoryId.ToString(CultureInfo.InvariantCulture);
                    }
                    this.lnkEditCategory.NavigateUrl = this.lnkEditCategory.NavigateUrl + "&productId=" + product.ProductId.ToString(CultureInfo.InvariantCulture);
                    this.litralProductTag.SelectedValue = tagsId;
                    if (tagsId.Count > 0)
                    {
                        foreach (int num in tagsId)
                        {
                            this.txtProductTag.Text = this.txtProductTag.Text + num.ToString() + ",";
                        }
                        this.txtProductTag.Text = this.txtProductTag.Text.Substring(0, this.txtProductTag.Text.Length - 1);
                    }
                    this.dropProductTypes.DataBind();
                    this.dropBrandCategories.DataBind();
                    this.LoadProduct(product, dictionary, pv);
                }
            }
        }

        private bool ValidateConverts(bool skuEnabled, out int displaySequence, out decimal salePrice, out decimal? costPrice, out decimal? marketPrice, out int stock, out decimal? weight)
        {
            string str = string.Empty;
            costPrice = 0;
            marketPrice = 0;
            weight = 0;
            displaySequence = stock = 0;
            salePrice = 0M;
            if (string.IsNullOrEmpty(this.txtDisplaySequence.Text) || !int.TryParse(this.txtDisplaySequence.Text, out displaySequence))
            {
                str = str + Formatter.FormatErrorMessage("请正确填写商品排序");
            }
            if (this.txtProductCode.Text.Length > 20)
            {
                str = str + Formatter.FormatErrorMessage("商家编码的长度不能超过20个字符");
            }
            if (!string.IsNullOrEmpty(this.txtMarketPrice.Text))
            {
                decimal num;
                if (decimal.TryParse(this.txtMarketPrice.Text, out num))
                {
                    marketPrice = new decimal?(num);
                }
                else
                {
                    str = str + Formatter.FormatErrorMessage("请正确填写商品的市场价");
                }
            }
            if (!skuEnabled)
            {
                if (string.IsNullOrEmpty(this.txtSalePrice.Text) || !decimal.TryParse(this.txtSalePrice.Text, out salePrice))
                {
                    str = str + Formatter.FormatErrorMessage("请正确填写商品一口价");
                }
                if (!string.IsNullOrEmpty(this.txtCostPrice.Text))
                {
                    decimal num2;
                    if (decimal.TryParse(this.txtCostPrice.Text, out num2))
                    {
                        costPrice = new decimal?(num2);
                    }
                    else
                    {
                        str = str + Formatter.FormatErrorMessage("请正确填写商品的成本价");
                    }
                }
                if (string.IsNullOrEmpty(this.txtStock.Text) || !int.TryParse(this.txtStock.Text, out stock))
                {
                    str = str + Formatter.FormatErrorMessage("请正确填写商品的库存数量");
                }
                if (!string.IsNullOrEmpty(this.txtWeight.Text))
                {
                    decimal num3;
                    if (decimal.TryParse(this.txtWeight.Text, out num3))
                    {
                        weight = new decimal?(num3);
                    }
                    else
                    {
                        str = str + Formatter.FormatErrorMessage("请正确填写商品的重量");
                    }
                }
            }
            if (!string.IsNullOrEmpty(str))
            {
                this.ShowMsg(str, false);
                return false;
            }
            return true;
        }
    }
}

